import org.junit.Test;

/**
 * String的基本使用:体现String的不可变性
 */
public class StringTest1 {
    @Test
    public void test1() {
        String s1 = "abc";//字面量定义的方式，"abc"存储在字符串常量池中
        String s2 = "abc";//s2指向常量池相同的地方(相同的地址引用)
        System.out.println(s1 == s2);//判断地址：true
        s1 = "hello";
        System.out.println(s1 == s2);//判断地址：true  --> false

        System.out.println(s1);//hello
        System.out.println(s2);//abc，因为s1从新开辟了一个空间赋值· 不会影响s1

    }

    @Test
    public void test2() {
        String s1 = "abc";
        String s2 = "abc";
        s2 += "def";
        System.out.println(s2);//abcdef
        System.out.println(s1);//abc
    }

    @Test
    public void test3() {
        String s1 = "abc";
        String s2 = s1.replace('a', 'm');
        System.out.println(s1);//abc
        System.out.println(s2);//mbc
    }
    @Test
    public void test1x() {
        String s = "1";//4774
        String s2 = "12";
        String s3 = "13";
        String s4 = "14";
        String s5 = "15";
        String s6 = "16";
        String s7 = "17";
        String sx = "1";//4774
        String sx1 = "12";
        String sx3 = "13";
        String sx4 = "14";
        String sx5 = "15";
        String sx6 = "16";
        String sx7 = "17";
    }
}


